package com.by.toolkitspring.dynamictp;

import com.by.toolkit.platform.ByContext;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class ByDynaimcTpRunnable implements Runnable {

    private final Runnable runnable;

    private final Map<String, String> parentContext;

    public ByDynaimcTpRunnable(Runnable runnable, Map<String, String> parentContext) {
        this.runnable = runnable;
        this.parentContext = parentContext;
    }

    @Override
    public void run() {
        ByContext.putAll(parentContext);
        //log.info("[ByDynaimcTpRunnable][run] parentContext:[{}]", parentContext);
        this.runnable.run();
        ByContext.remove();
    }
}
